
export const mixins = {
	data() {
		return {
			title1:(uni.getStorageSync('xgschool')||'今日')+'校果',
			mobile:''
		};
	},
	onShow(){
		this.mobile=uni.getStorageSync('xguserinfo').mobile
	},
	created() {},
	mounted() {},
	
	methods: {
		navto(url,type) {
			if(type==1||!type){
				uni.navigateTo({
					url
				})
			}else{
				uni.switchTab({
					url
				})
			}
			
		},
		back() {
			uni.navigateBack()
		},
		copy(text) {
			uni.setClipboardData({
				data: text,
				success: function() {
					uni.$u.toast('复制成功')
				}
			});
		},
		// 获取地址
		getaddr() {
			let _this = this
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
				},
				fail(r) {
		
				},
				complete(res) {
					if (res.errMsg == 'getLocation:fail network error') {
						
						_this.iskt = false
						uni.setStorageSync('schoolkt',_this.iskt)
						_this.loading=false
						return
					}
					uni.request({
						url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=WZ3BZ-ULE6F-KLVJ4-NH2D7-NALA2-HTBTW&get_poi=1`,
						success(r) {
							if (r.data.result.address_component.province == r.data.result
								.address_component.city) {
								_this.addrdetial = r.data.result.address_component.province
							} else {
								_this.addrdetial = r.data.result.address_component.province + r
									.data.result.address_component.city
							}
							_this.sf = r.data.result.address_component.province
							_this.city = r.data.result.address_component.city
							_this.checkaddr()
						}
					})
				}
			});
		},
		checkaddr(){
			let _this=this
			home.checkarea({
				province: _this.sf,
				city: _this.city
			}).then(res => {
				if (res.data.code == 200) {
					_this.iskt = true
					uni.setStorageSync('schoolkt',_this.iskt)
					uni.setStorage({
						key: 'schoolarea',
						data: res.data.data,
						success() {
							_this.getinit()
							_this.getnotice()
						}
					})
				} else {
					_this.iskt = false
				}
				_this.loading=false
			})
		},
		preview(urls, current) {
			let url = []
			urls.map(t => {
				url.push(this.URL(t))
			})
			uni.previewImage({
				urls: url,
				current
			});
		},
		navtosw(url){
			uni.switchTab({
				url
			})
		}
	},
	computed: {
		URL() {
			return (url) => {
				if (url?.includes('https:') || url?.includes('data:image/') || url?.includes('http:')) {
					return url
				} else {
					return 'http://we.fuliaoxx.com' + url
				}


				// return url.includes('https:') ? url : this.$BASE_URL + url
			}
		},

		/**
		 * 根据出生日期算出年龄
		 */
		getAge() {
			return (strBirthday) => {
				var returnAge;
				var strBirthdayArr = strBirthday.split("-");
				var birthYear = strBirthdayArr[0];
				var birthMonth = strBirthdayArr[1];
				var birthDay = strBirthdayArr[2];

				var d = new Date();
				var nowYear = d.getFullYear();
				var nowMonth = d.getMonth() + 1;
				var nowDay = d.getDate();

				if (nowYear == birthYear) {
					returnAge = 0; //同年 则为0岁
				} else {
					var ageDiff = nowYear - birthYear; //年之差
					if (ageDiff > 0) {
						if (nowMonth == birthMonth) {
							var dayDiff = nowDay - birthDay; //日之差
							if (dayDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						} else {
							var monthDiff = nowMonth - birthMonth; //月之差
							if (monthDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						}
					} else {
						returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
					}
				}
				return returnAge; //返回周岁年龄
			}
		}


	}
};